/**
 * 车次管理管理初始化
 */
var Vehicle = {
    id: "VehicleTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Vehicle.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '车辆类型', field: 'vehicleType', visible: false, align: 'center', valign: 'middle', sortable: true},
        {title: '车次', field: 'vehicleNo', align: 'center', valign: 'middle', sortable: true},
        {title: '发车时刻', field: 'departTime', align: 'center', valign: 'middle', sortable: true},
        {title: '到达时刻', field: 'arrTime', align: 'center', valign: 'middle', sortable: true},
        {title: '始发站', field: 'departure', align: 'center', valign: 'middle', sortable: true},
        {title: '终点站', field: 'terminus', align: 'center', valign: 'middle', sortable: true},
        {title: '耗时(分钟)', field: 'costTime', align: 'center', valign: 'middle', sortable: true}
    ];
};

/**
 * 检查是否选中
 */
Vehicle.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Vehicle.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加车次管理
 */
Vehicle.openAddVehicle = function () {
    var index = layer.open({
        type: 2,
        title: '添加车次管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vehicle/vehicle_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看车次管理详情
 */
Vehicle.openVehicleDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '车次管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vehicle/vehicle_update/' + Vehicle.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除车次管理
 */
Vehicle.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/vehicle/delete", function (data) {
            Feng.success("删除成功!");
            Vehicle.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("vehicleId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询车次管理列表
 */
Vehicle.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Vehicle.table.refresh({query: queryData});
};


/**
 * 打开查看票价详情
 */
Vehicle.openTicketPriceDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: Vehicle.seItem.vehicleNo+'票价详情',
            area: ['100%', '99%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vehicle/ticketPrice_detail/' + Vehicle.seItem.id
        });
        this.layerIndex = index;
    }
};


/**
 * 打开查看座位详情
 */
Vehicle.openTrainSeatDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '座位详情',
            area: ['100%', '99%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vehicle/trainSeat_detail/' + Vehicle.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 打开查看车站详情
 */
Vehicle.openStationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '车站详情',
            area: ['100%', '99%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vehicle/staion_detail/' + Vehicle.seItem.id
        });
        this.layerIndex = index;
    }
};


$(function () {
    var defaultColunms = Vehicle.initColumn();
    var table = new BSTable(Vehicle.id, "/vehicle/list", defaultColunms);
    table.setPaginationType("client");
    Vehicle.table = table.init();
});
